/*
 * T.Raynal - A.Aviles - F.Diallo
 * XML-Scenarios
 * PPA AL5-2
 * December 2012 
 */
package model.expression;

import java.io.Serializable;

import model.Expression;
import model.Operator;
import model.serialization.XmlSerializable;
import model.serialization.XmlElement;
import common.Commons.EXPRESSION_TYPE;
import common.Commons.OPERATORS;
import common.Commons.RESULT;
import common.exception.UnsupportedOperatorException;
import common.interfaces.IEvaluable;
import common.OperatorRegister;

// TODO: Auto-generated Javadoc
/**
 * Represent a Dynamic Expression, i.e complex evaluation on strings
 */
@XmlElement(name = "EXPRESSION")
public class DynamicExpression extends Expression implements IEvaluable, XmlSerializable, Serializable {

	private static final long serialVersionUID = 1L;

	/**
	 * Instantiates a new dynamic expression.
	 *
	 * @param Label
	 * @param Result
	 */
	@SuppressWarnings("serial")
	public DynamicExpression(String label, String result) {
		super(label, result, EXPRESSION_TYPE.DYNA,
				new EvaluateeHandler() {
					@Override
					public boolean valid(String evaluatee) {
						boolean result =true;	
						if (null==evaluatee)
							result= false;
							return result;
					}
				}	
				);
		_register = OperatorRegister.getOperators(OPERATORS.DYNAMIC);
		_resultType = RESULT.ALPHANUMERIC;
	}

	/* (non-Javadoc)
	 * @see model.Expression#register(model.Operator)
	 */
	@Override
	public void register (Operator operator) throws UnsupportedOperatorException
	{
		if (operator.getType()==OPERATORS.ARITMETIC || operator.getType()==OPERATORS.LOGICAL)
			throw new UnsupportedOperatorException(operator.getId());
		_register.add(operator.getId());
	}

}
